package com.cloudptt.api.product.func.media.device;

import java.util.Iterator;
import java.util.Set;

import com.cloudptt.api.comm.Const;
import com.cloudptt.api.product.func.media.EventListener;
import com.cloudptt.api.product.log.Log;

import android.bluetooth.BluetoothHeadset;
import android.content.Intent;
import android.content.IntentFilter;

public class DefaultDevKey implements IDeviceKey {

	public DefaultDevKey(){
		
	}

	public final static String THIS_FILE = "DefaultDevKey";
	private static final String BRAND = "Leadcore";
	private static final String DEVICE = "cx1881evb_arm64";
	private static final String MODEL = "L1861";
	
	private IntentFilter mFilter;
	
	/**ָ��PTT**/
	 private final static String ACTION_PTT_DOWN = "com.hytera.ptt.down";
	 private final static String ACTION_PTT_UP = "com.hytera.ptt.up";

	
	public static boolean isThisDev(String brand,String device,String model){
		if(brand == null
				|| device == null
				|| model == null)
		{
			return false;
		}
		else if(BRAND.equals(brand)
				&& DEVICE.equals(device)
				&& MODEL.equals(model)){
			return true;
		}
		return false;
	}
	
	@Override
	public IntentFilter getBstIntentFilter() {
		mFilter = new IntentFilter();
		/**����PTT**/
		mFilter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
		mFilter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY+"."+Integer.toString(0x1001));
		mFilter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY+"."+Integer.toString(0x1002));
		mFilter.addAction(ACTION_PTT_DOWN);/**����ָ��PTT**/
		mFilter.addAction(ACTION_PTT_UP);/**����ָ��PTT**/
	
		return mFilter;
	}
	
	@Override
	public void procBst(Intent intent, EventListener listener) {
		String action = intent.getAction();
		if(action.equals(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT)){
			Set<String> info = intent.getCategories();
			Iterator it1 = info.iterator();
			String strInfo = (String) it1.next();
			String ptt_down = BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY+ "." + Integer.toString(0x1001);
			String ptt_up = BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY+ "." + Integer.toString(0x1002); 
			if(ptt_down.equals(strInfo)){
				Log.d(THIS_FILE, " PTT_DOWN");
				if (listener != null) {
					listener.onPtt(Const.MSG_TALK_ON,false,false,true,false);
				}
			}else if(ptt_up.equals(strInfo)){
				Log.d(THIS_FILE, " PTT_UP");
				if (listener != null) {
					listener.onPtt(Const.MSG_TALK_OFF,false,false,true,false);
				}
			}
		}else if(action.equals(ACTION_PTT_DOWN)){
			Log.d(THIS_FILE, " ACTION_PTT_DOWN");
			if (listener != null) {
				listener.onPtt(Const.MSG_TALK_ON,false,false,true,false);
			}
		}else if(action.equals(ACTION_PTT_UP)){
			Log.d(THIS_FILE, " ACTION_PTT_UP");
			if (listener != null) {
				listener.onPtt(Const.MSG_TALK_OFF,false,false,true,false);
			}
		}
	}
}
